package cn.kgc.watch.web;

import cn.kgc.watch.entity.*;
import cn.kgc.watch.entity.vo.PageInfoVo;
import cn.kgc.watch.service.AttributeService;
import cn.kgc.watch.service.BrandService;
import cn.kgc.watch.service.CommoditySkuService;
import cn.kgc.watch.service.CommoditySpuService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/products")
public class ProductsListController {
    @Autowired
    private CommoditySkuService commoditySkuService;
    @Autowired
    private CommoditySpuService commoditySpuService;
    @Autowired
    private BrandService brandService;
    @Autowired
    private AttributeService attributeService;
    //获得所有商品 并添加搜索条件 暂时无分页 搜素的是商品属性
    @PostMapping("/list")
    public ResultInfo findAll(@RequestBody Specification specification){
        if (specification.getPageNum()==0){
            specification.setPageNum(1);
        }
        System.out.println("specification = " + specification.getTitle());
        //？ 如果我重复搜素的话是什么情况
        PageInfo<CommoditySpu> commoditySpuList=this.commoditySpuService.findAll(specification);
        if (commoditySpuList.getSize()!=0){
            return  new ResultInfo(200,"查询成功",commoditySpuList);
        }else {
            return  new ResultInfo(401,"抱歉没有你要找的商品",commoditySpuList);
        }

    }
    //获取所有品牌信息
    @GetMapping("/brandList")
    public ResultInfo brandList(){
       List<Brand> brandList= this.brandService.findAll();
       return new ResultInfo(200,"查询成功",brandList);
    }
    //获取所有属性
    @GetMapping("/attributeList")
    public ResultInfo attributeList(){
        List<Attribute> attributeList=this.attributeService.findAll();
        return new ResultInfo(200,"查询成功",attributeList);
    }
    //对评论进行审核

    @GetMapping("/selectSpu")
    public ResultInfo selectSpu(Integer id){
        CommoditySku commoditySku=this.commoditySkuService.findAll(id);
        return new ResultInfo(200,"查询成功",commoditySku);
    }


}
